# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=3

PYTHON_DEPEND="*:2.5"

inherit distutils eutils

MY_PN="timingandestimationplugin"
MY_PV="trac${PV}"
MY_P="${MY_PN}-${MY_PV}"

DESCRIPTION="Plugin that adds estimation and time tracking to Trac."
HOMEPAGE="http://trac-hacks.org/wiki/TimingAndEstimationPlugin"
SRC_URI="permissions? (
			http://trac-hacks.org/changeset/latest/${MY_PN}/branches/${MY_PV}-Permissions?old_path=/&format=zip	-> ${PN}-${MY_PV}-Permissions.zip )
		!permissions? (
			http://trac-hacks.org/changeset/latest/${MY_PN}/branches/${MY_PV}?old_path=/&format=zip -> ${PN}-${MY_PV}.zip )"

LICENSE="as-is"
SLOT="0"
KEYWORDS="~x86"
IUSE="
	git
	permissions
	subversion
	"

DEPEND="app-arch/unzip"
RDEPEND="
		=www-apps/trac-0.12*
		git? ( dev-vcs/git )
		subversion? ( dev-vcs/subversion )
		"

S="${WORKDIR}/${MY_PN}/branches/${MY_PV}"

src_unpack() {
	use permissions && S="${S}-Permissions"
	unpack ${A}
}

src_install() {
	distutils_src_install

	if use git || use subversion ; then
		insinto /usr/share/${PN}
		doins scripts/trac-post-commit.py

		if use git ; then
			doins scripts/git_post_receive.py
			doins scripts/git-post-receive
		fi

		if use subversion ; then
			doins scripts/svn-post-commit.sh
		fi
	fi
}

pkg_postinst() {
	elog "To install the plugin for a desired environment \"foo\""
	elog "add this to its trac.ini:"
	elog "[components]"
	elog "timingandestimationplugin.* = enabled"
	elog ""
	elog "It is then required to upgrade the database:"
	elog "trac-admin /path/to/foo upgrade"
	elog ""
	elog "Restarting the webservice is required."
	
	if use git || use subversion ; then
		elog ""
		elog "Post commit hooks are located in /usr/share/${PN}"
	fi
}
